<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
    
<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />
  
<div class="modal-dialog demo2do-modal-dialog">

  <div class="modal-content">

    <div class="modal-header earth-breadcrumb no-bottom-border clearfix">

      <h2><i class="glyphicon glyphicon-fire" title=""></i>&nbsp;&nbsp;<span>打款</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" class ="form-horizontal"  data-validate ="true">

      <input type="hidden" name="orderId" value="${order.id }" id="orderId" >

      <div class="modal-body">

        <div class="form-group demo2do-form-group">

          <label class="col-xs-2 control-label">打款金额</label>
          <div class="col-xs-4">
            <input type="number" step="1" min="0" required="required" class="form-control" name="payAmount" id="payAmount" value="${order.totalRent }"/>
          </div>

          <label class="col-xs-2 control-label">处理方式</label>
          <div class="col-xs-4">
            <select class="form-control" name="repayType" id="repayType" disabled="disabled">
              <c:forEach var="repaymentType" items="${RepaymentType}">
                <option value="${repaymentType.ordinal() }" <c:if test="${order.repaymentType.ordinal() eq repaymentType.ordinal() }">selected="selected"</c:if>><fmt:message key="${repaymentType.key}" /></option>
              </c:forEach>
            </select>
          </div>

        </div>
        
        <div class="form-group demo2do-form-group">
        
          <label class="col-xs-4 control-label">帐号</label>

          <div class="col-xs-5">
            <input type="text" class="form-control" name="accountNo" id="accountNo" value="${account.accountNo }" disabled="disabled"/>
          </div>
          
          <label class="col-xs-4 control-label">户名</label>

          <div class="col-xs-5">
            <input type="text" class="form-control" name="accountName" id="accountName" value="${account.accountName }" disabled="disabled"/>
          </div>

        </div>
        <div class="form-group demo2do-form-group">
          <label class="col-xs-4 control-label">备注</label>

          <div class="col-xs-5">
            <input type="text" class="form-control" name="remark" id="remark" value="${order.orderNo }"/>
          </div>
        </div>

      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-success btn-shadow btn-shadow-success demo2do-btn" id="payBtn">确认打款</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default demo2do-btn" data-dismiss="modal">取消</button>
      </div>

    </form>

  </div>

</div>

<!-- <script type="text/javascript">

  $(document).ready(function() {
  
     $("form").ajaxForm({
         url:'${ctx}/orders/detail/doPay',
         type:'POST',
         success:function(data){
             var jsonData=$.parseJSON(data);
             
             $('#dialog').find('.modal-body p').text(jsonData.message).end().modal();
         }
       });

     $('.select-select2').select2({
      minimumInputLength: -1,
     });
      
  });

</script> -->

   <script type="text/javascript">
  
     $("#payBtn").click(function(){
        $('#payBtn').attr('disabled',"true");
        $('#payBtn').html("打款中……");
        var orderId = $("#orderId").val();
        var payAmount = $("#payAmount").val();
        var accountNo = $("#accountNo").val();
        var accountName = $("#accountName").val();
        var remark = $("#remark").val();
        $.ajax({
  
          type:'POST',
             url:'${ctx}/orders/detail/doPay',
             data:{'orderId':orderId,'payAmount':payAmount,'accountNo':accountNo,'accountName':accountName,'remark':remark},
             dataType: 'json',
             error: function(){
                 $('.close').click();
                 alert('网络错误！稍后再试！');
                 $('#payBtn').removeAttr("disabled");
                 $('#payBtn').html("扣款");
             },
             success:function(data){
            	 $('.close').click();
               $('#dialog').find('.modal-body p').text(data.message).end().modal();
               
             }
        });
    }); 
  </script>

<script>
    $("#closeBtn").bind("click", function(){
      var orderId = $("#orderId").val();
      window.location.href = "${ctx}/orders/all/"+orderId+"/detail";
    });
</script>

<div class="modal fade" id="dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">提示</h4>
      </div>
      <div class="modal-body">
        <p></p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeBtn">关闭</button>
      </div>
    </div>
  </div>
</div>
